<?php 
$db_name='zips';
$dir="backups/$db_name";
if(!is_dir($dir))
{
	if(!@mkdir($dir))
	{
		die("backup directory $dir cloud not be creat");
	}
}
$time=time();
$dbc=@mysqli_connect('localhost','root','root',$db_name) or die("the database could not be backup");
//检索数据库中的表
$r=mysqli_query($dbc,'SHOW TABLES');
if(mysqli_num_rows($r)>0)
{
	echo "正在备份中..............";
	while(list($table)=mysqli_fetch_array($r,MYSQL_NUM))
	{
		$q="select * from $table";
		$r2=mysqli_query($dbc,$q);
		if(mysqli_num_rows($r2)>0)
		{
			if($fp=gzopen("$dir/{$table}_{$time}.sql.gz",'w9'))
			{
				while($row=mysqli_fetch_array($r2,MYSQL_NUM))
				{
					foreach($row as $value)
					{
						$value=addslashes($value);
						gzwrite($fp, "'$value', ");
					}
					gzwrite($fp, "\n");
				}
				gzclose($fp);
				echo "the $table has benn backuped.......";
			}
		}
	}
}
 ?>